package department;

import java.io.IOException;
import course.shared.PMF;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.jdo.PersistenceManager;
import college.College;


/**
 * Servlet implementation class addDepServlet
 */
public class addDepServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static final String nextJSP = "";

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		
		String name = request.getParameter("name");
		Long college = Long.parseLong(request.getParameter("college"));
		
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try{
			College c = pm.getObjectById(College.class,college);
			c.addDep(name, c);
		} finally {
		    pm.close();
		}
		
		response.sendRedirect(nextJSP);
		return;
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
